<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Collection底层实现迭代器
 * @author 张皓旻
 *
 */
class Collection_iterator implements Iterator
{
    /**
     * 指针位置
     * @var int
     */
    private $_position = 0;

    /**
     * Eloquent的容器
     * @var array
     */
    protected $_items = array();
    
    public function __construct()
    {
        $this->_position = 0;
    }
    
    public function current ()
    {
        return $this->_items[$this->_position];
    }
    
    public function next ()
    {
        ++ $this->_position;
    }
    
    public function key ()
    {
        return $this->_position;
    }
    
    public function valid ()
    {
        return isset($this->_items[$this->_position]);
    }
    
    public function rewind ()
    {
        $this->_position = 0;
    }
}